home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / boot / czesc_2 / popper / sources / cutimage.c next >
C/C++ Source or Header  |  1993-12-12  |  3KB  |  175 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <exec/types.h>
  5. #include <exec/memory.h>
  6. #include <dos/dos.h>
  7. #include <dos/dosextens.h>
  8. #include <dos/dostags.h>
  9. #include <intuition/intuition.h>
  10. #include <libraries/popper.h>
  11.  
  12. #include <proto/graphics.h>
  13. #include <proto/dos.h>
  14. #include <proto/layers.h>
  15. #include <proto/intuition.h>
  16. #include <proto/exec.h>
  17. #include <proto/console.h>
  18. #include <proto/popper.h>
  19.  
  20. #include <pragmas/dos_pragmas.h>
  21. #include <pragmas/layers_pragmas.h>
  22. #include <pragmas/intuition_pragmas.h>
  23. #include <pragmas/graphics_pragmas.h>
  24. #include <pragmas/exec_pragmas.h>
  25. #include <pragmas/console_pragmas.h>
  26.  
  27. #define MakeID(a,b,c,d) ((ULONG)(a)<<24L|(ULONG)(b)<<16L|(c)<<8|(d))
  28.  
  29. ULONG *GetFile (char *Name);
  30. void main (UWORD argc,char **argv);
  31. void GetImage (ULONG *Buffer, struct Image *Image);
  32. VOID Err (char *string);
  33. extern struct Library *DOSBase;
  34.  
  35. void main (UWORD argc,char **argv)
  36. {
  37.     struct Image Image;
  38.     ULONG *Buffer;
  39.     struct Library *PopperBase;
  40.     UWORD i;
  41.  
  42.     if (argc < 2 || argv[1][0] == '?')
  43.     {
  44.         Err ("Usage: CutImage [A ASAImage] [AL ASALowRes] [M MenuImage] [ML MenuLowRes]\nExample: CutImage M s:NewMenu.brush ML s:LowMenu.brush\n");
  45.         exit (5);
  46.     }
  47.  
  48.     if ( !(PopperBase = OpenLibrary ("popper.library", 2L)))
  49.     {
  50.         Err ("The popper.library is not installed !\n");
  51.         exit (10);
  52.     }
  53.  
  54.     i = 1;
  55.  
  56.     while (i < argc - 1)
  57.     {
  58.         Buffer = GetFile (argv[i+1]);
  59.         if (Buffer)
  60.         {
  61.             GetImage (Buffer, &Image);
  62.             if (Image.Width && Image.Height && Image.ImageData)
  63.             {
  64.                 if ( stricmp (argv[i], "A") == 0)
  65.                 {
  66.                     SetASAImage (&Image, NULL);
  67.                 }
  68.                 else if ( stricmp (argv[i], "AL") == 0)
  69.                 {
  70.                     SetASAImage (NULL, &Image);
  71.                 }
  72.                 else if ( stricmp (argv[i], "M") == 0)
  73.                 {
  74.                     SetMenuImage (&Image, NULL);
  75.                 }
  76.                 else if ( stricmp (argv[i], "ML") == 0)
  77.                 {
  78.                     SetMenuImage (NULL, &Image);
  79.                 }
  80.                 else
  81.                 {
  82.                     Err ("The options ");
  83.                     Err (argv[i]);
  84.                     Err (argv[i+1]);
  85.                     Err (" are ignored.\n");
  86.                 }
  87.             }
  88.  
  89.             FreeMem (Buffer, Buffer[0]);
  90.         }
  91.         else
  92.         {
  93.             Err ("The file ");
  94.             Err (argv[i+1]);
  95.             Err (" cannot be opened.\n");
  96.         }
  97.  
  98.         i += 2;
  99.     }
  100.  
  101.     CloseLibrary (PopperBase);
  102.     exit (0);
  103. }
  104.  
  105.  
  106. void GetImage (ULONG *Buffer, struct Image *Image)
  107. {
  108.     UWORD *Temp;
  109.     ULONG i;
  110.  
  111.     if ( *(Buffer + 1) == MakeID ('F','O','R','M') )
  112.     {
  113.         Image->ImageData = NULL;
  114.         Image->Width = 0;
  115.         if ( *(Buffer + 3) == MakeID ('I','L','B','M') )
  116.         {
  117.             Temp = (UWORD *)Buffer + 8;
  118.             i = Buffer[0];
  119.             while (i)
  120.             {
  121.                 if (*(ULONG *)Temp == MakeID ('B','M','H','D') )
  122.                 {
  123.                     Image->Width = *(Temp + 4);
  124.                     Image->Height = *(Temp + 5);
  125.                     Image->LeftEdge = 0;
  126.                     Image->TopEdge = 0;
  127.                     Image->Depth = 1;
  128.                     Image->PlanePick = 1;
  129.                     Image->PlaneOnOff = 0;
  130.                     Image->NextImage = NULL;
  131.                 }
  132.                 if (*(ULONG *)Temp == MakeID ('B','O','D','Y') )
  133.                 {
  134.                     Image->ImageData = Temp + 4;
  135.                 }
  136.                 i -= 2;
  137.                 Temp++;
  138.             }
  139.         }
  140.     }
  141. }
  142.  
  143.  
  144. ULONG *GetFile (char *Name)
  145. {
  146.     BPTR File;
  147.     ULONG *Buffer, Len;
  148.     File = Open (Name, MODE_OLDFILE);
  149.     if (File)
  150.     {
  151.         Seek (File, 0, OFFSET_END);
  152.         Len = Seek (File, 0, OFFSET_BEGINNING);
  153.         Buffer = AllocMem (Len+4, 0L);
  154.         if (Buffer)
  155.         {
  156.             Buffer[0] = Len+4;
  157.             Read (File, Buffer+1, Len);
  158.         }
  159.         Close (File);
  160.     }
  161.     else
  162.     {
  163.         Buffer = NULL;
  164.     }
  165.     return Buffer;
  166. }
  167.  
  168.  
  169. VOID Err (char *string)
  170. {
  171.     BPTR out = Output();
  172.     if (out)
  173.         Write (out, string, strlen (string));
  174. }
  175.